#! /usr/bin/env python
# -*- coding: utf-8 -*-

from playwright.sync_api import Page

from common.base_page import BasePage
from common.logger import logger
from locators.majorHazardSourceSafety.olMonitorWarn.alarmManage.loc_fire_alarm import LocFireAlarm
from locators.majorHazardSourceSafety.olMonitorWarn.alarmManage.loc_query import LocQuery


class AlarmManage(BasePage):

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('重大危险源安全管理')
        self.switch_menu('在线监测预警')
        self.switch_menu('报警管理')

    def query_total_list(self, device_type, index_type, device_name, alarm_start_time, alarm_end_time, alarm_type,
                         alarm_status, fire_start_time, fire_end_time, danger_type, danger_level, danger_name):
        logger.info('开始报警管理查询测试')
        logger.info('选择设备类型')
        self.select(LocQuery.loc_device_type, device_type)
        logger.info('选择指标类型')
        self.select(LocQuery.loc_index_type, index_type)
        logger.info('输入设备名称')
        self.fill(LocQuery.loc_device_name, device_name)
        logger.info('输入报警时间')
        self.fill_date_time(LocQuery.loc_alarm_time, alarm_start_time, alarm_end_time)
        logger.info('选择报警类型')
        self.select(LocQuery.loc_alarm_type, alarm_type)
        logger.info('选择报警状态')
        self.select(LocQuery.loc_alarm_status, alarm_status)
        logger.info('输入消警时间')
        self.fill_date_time(LocQuery.loc_fire_time, fire_start_time, fire_end_time)
        logger.info('选择重大危险源类型')
        self.select(LocQuery.loc_danger_type, danger_type)
        logger.info('选择重大危险源级别')
        self.select(LocQuery.loc_danger_level, danger_level)
        logger.info('输入重大危险源名称')
        self.fill(LocQuery.loc_danger_name, danger_name)
        self.click(LocQuery.loc_query, exact=True)

    def reset(self):
        """
        测试重置
        :return:
        """
        self.click(LocQuery.loc_reset, exact=True)

    def fire_alarm(self, fire_comment):
        # 只能对监控视频报警类型的告警进行消警
        logger.info('开始消警测试')
        logger.info('点击消警按钮')
        self.click(LocFireAlarm.loc_fire_button)
        logger.info('输入消警说明')
        self.fill(LocFireAlarm.log_fire_input, fire_comment)
        logger.info('提交')
        self.click(LocFireAlarm.loc_sumit_button)
